package org.hanyx;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.hanyx.grpc.hello.api.HelloRequest;
import org.hanyx.grpc.hello.api.HelloResponse;
import org.hanyx.grpc.hello.api.HelloServiceGrpc;


public class HelloClient {

    private static final String host = "127.0.0.1";
    private static final int port = 8977;

    public static void main(String[] args) {
        ManagedChannel channel = ManagedChannelBuilder
                .forAddress(host, port)
                .usePlaintext()
                .build();

        try {
            HelloServiceGrpc.HelloServiceBlockingStub helloService = HelloServiceGrpc.newBlockingStub(channel);
            HelloRequest request = HelloRequest
                    .newBuilder()
                    .setName("world")
                    .build();

            HelloResponse response = helloService.say(request);
            System.out.println(response.getMessage());
        } finally {
            channel.shutdown();
        }
    }
}
